package com.AAA.controller.sas;

import com.AAA.entity.LayData;
import com.AAA.entity.MyPage;
import com.AAA.entity.sas.TSasPlane;
import com.AAA.service.sas.TSasPlaneService;
import com.AAA.entity.User;
import com.github.pagehelper.PageInfo;
import org.springframework.web.bind.annotation.*;
import org.springframework.beans.factory.annotation.Autowired;

import javax.servlet.http.HttpSession;
import java.util.Date;

/**
 * (TSasPlane)表控制层
 *
 * @author 何泽明
 * @since 2022-10-28 17:23:15
 */
@RestController
@RequestMapping("tSasPlane")
public class TSasPlaneController {
    @Autowired
    private TSasPlaneService service;

    //分页
    @RequestMapping("queryAll")
    public LayData queryAll(MyPage myPage, TSasPlane tSasPlane){
        PageInfo pageInfo=service.query(myPage,tSasPlane);
        return new LayData(pageInfo);
    }

    //增 / 改
    @PostMapping("add")
    public LayData add(TSasPlane tSasPlane, HttpSession session){
        User user1 = (User) session.getAttribute("user");
        tSasPlane.setCreatetime(new Date());
        tSasPlane.setUid(user1.getId());
        if(tSasPlane.getId()==null){
            return new LayData(service.add(tSasPlane));
        }else{
            return new LayData(service.edit(tSasPlane));
        }
    }

    //状态
    @ResponseBody
    @PostMapping("updates")
    public LayData delete(TSasPlane tSasPlane){
        boolean status=service.updates(tSasPlane);
        return new LayData(status);
    }

    @GetMapping("getByCode")
    public LayData queryByQyCode(TSasPlane tSasPlane){
        return new LayData(service.queryByQyCode(tSasPlane));
    }
}

